﻿namespace BlamanticUI.Components;

/// <summary>
/// Render a table HTML tag.
/// </summary>
[CssClass("table")]
[HtmlTag("table")]
public class Table : BlazorParentComponentBase<Table>,
    IHasUIComponent,
    IHasSelectable,
    IHasColor,
    IHasCompact,
    IHasPadded,
    IHasVery,
    IHasSize,
    IHasBasic,
    IHasInverted,
    IHasCelled,IHasChildContent
{
    /// <summary>
    /// A segment of UI content for thead.
    /// </summary>
    [Parameter] public RenderFragment? HeadContent { get; set; }
    /// <summary>
    /// A segment of UI content for tbody.
    /// </summary>
    [Parameter]public RenderFragment? ChildContent { get; set; }
    /// <summary>
    /// A segment of UI content for tfoot.
    /// </summary>
    [Parameter] public RenderFragment? FootContent { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether to display border.
    /// </summary>
    /// <value>
    ///   <c>true</c> if has border; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Celled { get; set; }
    /// <summary>
    /// Gets or sets the striped style for alternative row.
    /// </summary>
    [Parameter] [CssClass("striped")] public bool Striped { get; set; }
    /// <summary>
    /// Gets or sets the first row and first column has a background color.
    /// </summary>
    [Parameter] [CssClass("definition")] public bool Definition { get; set; }
    /// <summary>
    /// Gets or sets the structured border of cells.
    /// </summary>
    [Parameter] [CssClass("structured")] public bool Structured { get; set; }
    /// <summary>
    /// Gets or sets the width of table is fixed.
    /// </summary>
    [Parameter] [CssClass("fixed")] public bool Fixed { get; set; }
    /// <summary>
    /// Gets or sets the text always in single line in cell.
    /// </summary>
    [Parameter] [CssClass("single line")] public bool SingleLine { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether hover style while cursor moving over items.
    /// </summary>
    /// <value>
    ///   <c>true</c> if selectable; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Selectable { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether collpse the space of text in cell.
    /// </summary>
    /// <value>
    ///   <c>true</c> if collapsing; otherwise, <c>false</c>.
    /// </value>
    [Parameter] [CssClass("collapsing")] public bool Collapsing { get; set; }
    /// <summary>
    /// Gets or sets the color of table.
    /// </summary>
    [Parameter] public Color? Color { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether adapted inverted background by parent component.
    /// </summary>
    /// <value>
    ///   <c>true</c> if adapted; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Inverted { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether to compact space of text.
    /// </summary>
    /// <value>
    ///   <c>true</c> if compact; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Compact { get; set; }
    /// <summary>
    /// Gets or sets the size.
    /// </summary>
    [Parameter] public Size? Size { get; set; }
    /// <summary>
    /// Gets or sets a layout that can be automatically recognized
    /// </summary>
    [Parameter] public bool Very { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether this style is basic.
    /// </summary>
    /// <value>
    ///   <c>true</c> if basic; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Basic { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether text increasing padding space.
    /// </summary>
    /// <value>
    ///   <c>true</c> if padded; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Padded { get; set; }

    /// <summary>
    /// No responsive style of table.
    /// </summary>
    [Parameter] [CssClass("unstackable")] public bool Unstackable { get; set; }
    /// <summary>
    /// Appends frames representing an arbitrary fragment of content.
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="sequence"></param>
    protected override void AddContent(RenderTreeBuilder builder, int sequence)
    {
        builder.CreateElement(0, "thead", HeadContent, condition: HeadContent is not null);
        builder.CreateElement(1, "tbody", ChildContent, condition: ChildContent is not null);
        builder.CreateElement(2, "tfoot", FootContent, condition: FootContent is not null);
    }
}
